package cn.imokay.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        new Thread(new MyThread1(),"MyThread1");

        FutureTask futureTask1 = new FutureTask<Integer>(new MyThread2());

        FutureTask<Integer> futureTask2 = new FutureTask<>(() -> 999);

        new Thread(futureTask1).start();
        new Thread(futureTask2).start();

        while (!futureTask1.isDone() && !futureTask2.isDone()) {
            System.out.println("wait...");
        }
        System.out.println(futureTask1.get());
        System.out.println(futureTask2.get());
    }

}

class MyThread1 implements Runnable {
    @Override
    public void run() {

    }
}

class MyThread2 implements Callable {
    @Override
    public Integer call() throws Exception {
        return 993339;
    }
}
